initTable=function (){
    let email = sessionStorage.getItem('email');
    let data = {}
    data.email = email;
    data.action = "get_friends";
    $.post("./action",data,function(json) {
        json = JSON.parse(json);
        if(json.result === 1 || json.result === "1"){
            let list=json.aaData;
            let html="";
            if(list!==undefined && list.length>0){
                for(let i=0;i<list.length;i++){
                    let record=list[i];
                    html = html +
                        "<div class=\"item \">" +
                        "<img class='profile' src=\"/chat"+record.url+"\" width=\"60\" height=\"60\" alt=''>"+
                        "<div>" +
                        "<div class='friend_name'>"+record.name+"</div>"+
                        "<div class='friend_email'>"+record.email+"</div>"+
                        "</div>"+
                        // "<h4 style='color: white; text-align: center'>  "+record.name+"  </h4>"+
                        "<button id=\"chatButton\" type=\"button\" class=\"btn btn-primary\"" +
                        " style='float: right; margin-right: 10px;margin-top: 1%' onclick=\'toChat(\""+record.email+"\",\""+record.name+"\",\""+record.url+"\")\'>聊天</button>"+
                        "</div>";
                }
            }
            $("#friendTable").html(html);
        }
        else {
            alert(json.reason);
        }
    })
}

toChat=function (email,name,url){
    sessionStorage.removeItem('toEmail');
    sessionStorage.removeItem('toName');
    sessionStorage.removeItem('toUrl');
    sessionStorage.setItem('toEmail', email);
    sessionStorage.setItem('toName', name);
    sessionStorage.setItem('toUrl', url);
    window.location.href="./chat.html";
}
initTable();
